<?php
class musermanagement extends CI_Model{
	var $user = "user_management";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_user,$username,$password,$email_user,$enable_user)
	{
		$this->id_user= $id_user;
		$this->username= $username;
		$this->password= $password;
		$this->email_user= $email_user;
		$this->enable_user= $enable_user;
	}
	
	function getList($page,$uri_segment){
		$query = $this->db->get($this->user, $page, $uri_segment);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getComboList(){
		$query = $this->db->get($this->user);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{	
		$arrayData = array(
			'id_user'=>$this->id_user,
			'username'=>$this->username,
			'password'=>$this->password,
			'email_user'=>$this->email_user,
			'enable_user'=>$this->enable_user
		);
		return $this->db->insert($this->user, $arrayData);
	}
	
	function update($id_user)
	{
		$arrayData = array(
			'username'=>$this->username,
			'password'=>$this->password,
			'email_user'=>$this->email_user,
			'enable_user'=>$this->enable_user
		);
		$this->db->where('id_user', $id_user);
		return $this->db->update($this->user, $arrayData);
	}
        
	function remove($id_user)
	{
		$this->db->where('id_user', $id_user);
		return $this->db->delete($this->user);
	}	
	
	function detail($id_user)
	{
		$this->db->where('id_user', $id_user);
		$query = $this->db->get($this->user);	
		return $query->result_array();
	}
	
	function getListSearch($name){
		$this->db->like('password',$name);
		$query = $this->db->get($this->user);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
}
?>